package com.atguigu.educms.controller;


import com.atguigu.commonutils.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-06-30
 */
@RestController
@RequestMapping("/educms/banneradmin")
public class BannerAdminController {

    @Autowired
    CrmBannerService bannerService;

    //分页查询banner
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page, @PathVariable long limit) {
        Page<CrmBanner> crmBannerPage = new Page<>(page,limit);

        bannerService.page(crmBannerPage,null);



        return R.ok().data("items",crmBannerPage.getRecords()).data("total",crmBannerPage.getTotal());
    }

    //add
    @PostMapping("addbanner")
    public R addBanner(@RequestBody CrmBanner crmBanner)
    {
        bannerService.save(crmBanner);
        return R.ok();
    }

    //delete
    @DeleteMapping("deletebanner/{id}")
    public R deleteBanner(@PathVariable String id)
    {
        bannerService.removeById(id);
        return R.ok();
    }

    @PutMapping("updatebanner")
    public R updatebanner(@RequestBody CrmBanner crmBanner)
    {
        bannerService.updateById(crmBanner);
        return R.ok();
    }

    //select
    @GetMapping("get/{id}")
    public R getbanner(@PathVariable String id)
    {
        CrmBanner byId = bannerService.getById(id);

        return R.ok().data("item",byId);
    }
}

